package com.neusoft.elm.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.neusoft.elm.dao.PointsDao;
import com.neusoft.elm.util.DBUtil;

public class PointsDaoImpl implements PointsDao{

		private Connection con = null;
		private PreparedStatement pst = null;
		private ResultSet rs = null;
	
	public int updateUserPoint(String userId , Integer point)throws Exception{
		String sql = "update points SET point = ? WHERE userId = ?";
        int result = 0;
        try {
        	con = DBUtil.getConnection();
            pst = con.prepareStatement(sql);
            pst.setInt(1, point);
            pst.setString(2, userId);
            pst.executeUpdate();
            result=pst.executeUpdate();
        } finally {
        	DBUtil.close(rs,pst);
        }

        return result; 


	}
	
	public int getPointById(String userId) throws Exception{
		    int point = 0;
		    StringBuffer sql = new StringBuffer();
		    sql.append("SELECT point FROM points WHERE userId=?");
		    try {
		        con = DBUtil.getConnection();
		        pst = con.prepareStatement(sql.toString());
		        pst.setString(1, userId);
		        rs = pst.executeQuery();
		        if (rs.next()) {
		        	point = rs.getInt("point");
		        }
		    } finally {
		        DBUtil.close(pst);
		    }
		    return point;
		
	}
	
}
